package com.homedo.microservice.open.service.gateway.manager.web.turbine;

import com.google.common.collect.Lists;
import com.netflix.config.DynamicPropertyFactory;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;

import java.util.List;

public class LocalDynamicDiscoveryClient implements DiscoveryClient {
    @Override
    public String description() {
        return "Local Dynamic Discovery Client";
    }

    @Override
    public ServiceInstance getLocalServiceInstance() {
        LocalServiceInstance serviceInstance = (LocalServiceInstance) DynamicPropertyFactory.getInstance().getContextualProperty("Turbine.LocalServiceInstance", null).getValue();
        return serviceInstance;
    }

    @Override
    public List<ServiceInstance> getInstances(String serviceId) {
        List<ServiceInstance> localServiceInstances = Lists.newArrayList();

        DynamicPropertyFactory.getInstance().getContextualProperty("Turbine.LocalServiceInstance", null).getValue();

        return localServiceInstances;
    }

    @Override
    public List<String> getServices() {
        return null;
    }
}
